var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
      login:0,
      username:'',
      userimg:'',
      ordernum:'',
      pjnum:'',
      msgnum:'',
      shopstatus:'',
      apply:'',
      shopid:'',
      show_enter:'',
      shop_type:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.checklogin();
      this.getstatus();
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      this.onLoad();
  },
  //获取用户信息 
  checklogin:function(){
      var status = wx.getStorageSync('status');
      var userid = wx.getStorageSync('userId');
      if(parseInt(status) > 0){
          this.setData({
            login:1
          })
          var that = this;
          var data={
            url: "api/userr/myData",
            data:{
              user_id:userid
            },
            success:function(e){
              console.log(e)
              that.setData({
                username:e.data.data.nickname,
                userimg: e.data.data.head,
                ordernum: e.data.data.demand_count,
                pjnum: e.data.data.evaluation_count,
                msgnum:e.data.data.msg_count,
                show_enter:e.data.data.show_enter
              });
            }
          };
          app.post(data);
      }else{
        this.setData({
          ordernum:0,
          pjnum:0,
          msgnum:0
        })
      }
  },
  // 获取我的数据
  checkuser:function(){
    var status = wx.getStorageSync('status');
    if(parseInt(status) > 0){
     
    }else{
      wx.showModal({
        title: '温馨提示',
        content: '为确保是您本人操作请验证手机号',
        confirmText: '确定',
        showCancel: true,
        success: function (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: '/pages/mine/mobile/mobile?type=40',
            })

          }

        }
      });
    }
    
  },
  seeorder:function(){
    var status = wx.getStorageSync('status');
    if (parseInt(status) > 0 ) {
      wx.navigateTo({
        url: '/pages/mine/orderType/index',
      })
    } 
    
  },
  seepingjia: function () {
    var status = wx.getStorageSync('status');
    if (parseInt(status) > 0) {
      wx.navigateTo({
        url: '/pages/mine/pingjiaType/index',
      })
    }
    
  },
  seenotice: function () {
    var status = wx.getStorageSync('status');
    if (parseInt(status) > 0) {
      wx.navigateTo({
        url: '/pages/mine/xiaoxi/xiaoxi',
      })
    } 
    
  },
  bangding: function () {
    var status = wx.getStorageSync('status');
    if (parseInt(status) > 0) {
      wx.navigateTo({
        url: '/pages/mine/aiche/aiche',
      })
    } else {
      wx.showModal({
        title: '温馨提示',
        content: '为确保是您本人操作请验证手机号',
        confirmText: '确定',
        showCancel: true,
        success: function (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: '/pages/mine/mobile/mobile?type=40',
            })

          }

        }
      });
    }

  },
  ziliao: function () {
    var status = wx.getStorageSync('status');
    if (parseInt(status) > 0) {
      wx.navigateTo({
        url: '/pages/mine/user-xx/user-xx',
      })
      
    } else {
      wx.showModal({
        title: '温馨提示',
        content: '为确保是您本人操作请验证手机号',
        confirmText: '确定',
        showCancel: true,
        success: function (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: '/pages/mine/mobile/mobile?type=40',
            })

          }

        }
      });
    } 

  },
  tousu: function () {
    var status = wx.getStorageSync('status');
    if (parseInt(status) > 0) {
      wx.navigateTo({
        url: '/pages/mine/advice/advice',
      })
    } else {
      wx.showModal({
        title: '温馨提示',
        content: '为确保是您本人操作请验证手机号',
        confirmText: '确定',
        showCancel: true,
        success: function (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: '/pages/mine/mobile/mobile?type=40',
            })

          }

        }
      });
    } 
  },
  ruzhu: function () {
    var status = wx.getStorageSync('status');
    var shop_type = this.data.shop_type;
    console.log('shop_type',shop_type);
    console.log('status', status);
    var role = wx.getStorageSync('role');
    console.log('role',role)
    if (parseInt(status) > 0) {
      if (this.data.apply == 1){
          if (parseInt(this.data.shopstatus) == 0) {
            wx.showToast({
              title: '你的店铺信息正在审核中，请等待',
              icon: 'none',
              duration: 2000
            })
          } else if (parseInt(this.data.shopstatus) == 2) {
            wx.navigateTo({
              url: '/pages/shangjia/shangjia-xx/shangjia-xx?id='+this.data.shopid,
            })

          } else if (this.data.shopstatus == 1) {
            if (parseInt(shop_type) == 2 && parseInt(role) == 1){
              wx.navigateTo({
                url: '/pages/shangjia/shangjia/shangjia',
              })
            } else if (parseInt(shop_type) == 2 && parseInt(role) == 2){
              wx.navigateTo({
                url: '/pages/shangjia/zichan/zichan',
              })

            }else if (parseInt(shop_type) == 3){
              wx.navigateTo({
                url: '/pages/new_doc/shangjia/shangjia',
              })  
            }else if(parseInt(shop_type) == 1){
              wx.navigateTo({
                url: '/pages/new_doc_wash/shangjia/shangjia',
              })  
            }  
           

          } else if (parseInt(this.data.shopstatus) == 3){
            wx.showToast({
              title: '你的店铺已下架',
              icon: 'none',
              duration: 2000
            })
          }else{
            wx.navigateTo({
              url: '/pages/shangjia/shangjia-xx/shangjia-xx',
            })
          }

      }else if(this.data.apply == 0){
          wx.navigateTo({
            url: '/pages/shangjia/shangjia-xx/shangjia-xx',
          })
        }
       

    } else {
      wx.showModal({
        title: '温馨提示',
        content: '为确保是您本人操作请验证手机号',
        confirmText: '确定',
        showCancel: true,
        success: function (res) {
          if (res.confirm) {
            wx.navigateTo({
              url: '/pages/mine/mobile/mobile?type=30',
            })

          }

        }
      });
    } 

  },

  // saoma
  saoma: function () {
    var _this = this;
    // 允许从相机和相册扫码
    wx.scanCode({
      success: (res) => {
        console.log(res)
        var path = res.path;
        wx.redirectTo({
          url: '/' + path,
        })
      }
    })
  },
  getstatus: function () {
    var userid = wx.getStorageSync('userId');
    var that = this;
    var param = {
      url: 'api/shop/applyStatus',
      data: {
        user_id: userid
      },
      success: function (e) {
        if (e.data.data.apply == 1){
          that.setData({
            shopstatus: e.data.data.status,
            apply: e.data.data.apply,
            shopid: e.data.data.shop_id,
            shop_type:e.data.data.shop_type,
          })
          wx.setStorageSync('shop_type', e.data.data.shop_type);
          wx.setStorageSync('shop_id', e.data.data.shop_id);
          wx.setStorageSync('role', e.data.data.role);
        }else if (e.data.data.apply == 0){
          that.setData({
            apply: e.data.data.apply,
            shopid: e.data.data.shop_id,
          })
          wx.setStorageSync('shop_id', e.data.data.shop_id)
        }
        
      }
    };
    app.post(param);
  },
  
  
})